﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebTraderLiteCL;

namespace WebTraderLite.Account
{
    public partial class ChangeAccountBal : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string user = System.Web.HttpContext.Current.User.Identity.Name.ToString();
            User curUser = new User(user);
            currBal.Text = curUser.getAccBalance().ToString();
        }

        protected void btnChangeBalance_Click(object sender, EventArgs e)
        {
            string user = System.Web.HttpContext.Current.User.Identity.Name.ToString();
            GenUser curUser = new GenUser(user);
            float oldBal = curUser.getAccBalance();
            float howMuch = (float)Convert.ToDouble(AddBalance.Text);
            if (oldBal == 0)
            {
                if (howMuch > 0)
                {
                    DBTransactions d = new DBTransactions();
                    d.updateAccountBalance(curUser,howMuch);
                    Response.Redirect("~/Account/ChangeAccountBal.aspx");
                }//end if
                else
                {
                    Error.Text = "You can't take that much out of this Account";
                }
            }//end if 
            if (oldBal + howMuch >= 0)
            {
                DBTransactions d = new DBTransactions();
                d.updateAccountBalance(curUser, howMuch);
                Response.Redirect("http://localhost:50716/Account/ChangeAccountBal.aspx");
            }
            else
            {
                Error.Text = "You can't take that much out of this Account";
            }
            

        }//end btnChangeInformation_Click
    }
}